<%@ page import="org.example.entity.Content" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Content content = (Content) request.getAttribute("content");
    if(content == null) {
        content = new Content(); // 双重保证
        content.setStatus("draft");
    }
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加内容 - 内容评级平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        /* 样式与原文件一致，略去重复内容 */
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4cc9f0;
            --dark: #1d3557;
            --darker: #0d1b2a;
            --light: #f8f9fa;
            --gray: #8d99ae;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --card-bg: rgba(29, 53, 87, 0.8);
            --transition: all 0.3s ease;
        }
        .main-content {
            max-width: 800px;
            margin: 2rem auto;
            padding: 0 2rem;
        }

        /* 表单区域 */
        .form-section {
            background: var(--card-bg);
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 3rem;
        }

        .section-title {
            font-size: 1.8rem;
            font-weight: 700;
            margin-bottom: 1.5rem;
            position: relative;
            padding-left: 1rem;
        }

        .section-title::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            width: 4px;
            background: var(--accent);
            border-radius: 2px;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .form-control {
            width: 100%;
            padding: 0.8rem 1rem;
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.05);
            color: var(--light);
            font-size: 1rem;
            transition: var(--transition);
        }

        .form-control:focus {
            outline: none;
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(76, 201, 240, 0.2);
        }

        textarea.form-control {
            min-height: 120px;
            resize: vertical;
        }

        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 1rem;
            margin-top: 2rem;
        }

        /* 类型特定字段样式 */
        .type-fields {
            display: none;
            margin-top: 15px;
            padding: 15px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            border-left: 3px solid var(--accent);
        }


    </style>
</head>
<body>
<!-- 页头、页脚与原文件一致 -->
<jsp:include page="header.jsp" />
<div class="main-content">
    <section class="form-section">
        <h1 class="section-title"><i class="fas fa-plus-circle"></i> 添加新内容</h1>
        <form action="${pageContext.request.contextPath}/content/add" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label for="title"><i class="fas fa-heading"></i> 标题</label>
                <input type="text" id="title" name="title" class="form-control" required>
            </div>
            <div class="form-group">
                <label for="type"><i class="fas fa-tag"></i> 类型</label>
                <select id="type" name="type" class="form-control" required>
                    <option value="">-- 请选择类型 --</option>
                    <option value="movie">电影</option>
                    <option value="book">图书</option>
                    <option value="music">音乐</option>
                </select>
            </div>
            <div class="form-group">
                <label for="cover"><i class="fas fa-image"></i> 封面图片</label>
                <input type="file" id="cover" name="cover" class="form-control" accept="image/*">
                <div id="cover-preview-container" style="margin-top: 10px; display: none;">
                    <span>封面预览:</span>
                    <img id="cover-preview" src="" alt="封面预览" style="max-width: 200px; max-height: 300px; margin-top: 5px;">
                </div>
            </div>
            <div class="form-group">
                <label for="description"><i class="fas fa-align-left"></i> 描述</label>
                <textarea id="description" name="description" class="form-control" required></textarea>
            </div>
            <!-- 类型特定字段 -->
            <div id="movie-fields" class="type-fields">
                <div class="form-group">
                    <label for="director"><i class="fas fa-user-tie"></i> 导演</label>
                    <input type="text" id="director" name="director" class="form-control">
                </div>
                <div class="form-group">
                    <label for="actors"><i class="fas fa-users"></i> 演员</label>
                    <input type="text" id="actors" name="actors" class="form-control">
                </div>
            </div>
            <div id="book-fields" class="type-fields">
                <div class="form-group">
                    <label for="author"><i class="fas fa-user-edit"></i> 作者</label>
                    <input type="text" id="author" name="author" class="form-control">
                </div>
                <div class="form-group">
                    <label for="publisher"><i class="fas fa-building"></i> 出版社</label>
                    <input type="text" id="publisher" name="publisher" class="form-control">
                </div>
            </div>
            <div id="music-fields" class="type-fields">
                <div class="form-group">
                    <label for="artist"><i class="fas fa-user"></i> 艺术家</label>
                    <input type="text" id="artist" name="artist" class="form-control">
                </div>
                <div class="form-group">
                    <label for="album"><i class="fas fa-compact-disc"></i> 专辑</label>
                    <input type="text" id="album" name="album" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="status"><i class="fas fa-check-circle"></i> 状态</label>
                <select id="status" name="status" class="form-control">
                    <option value="draft">草稿</option>
                    <option value="published">已发布</option>
                    <option value="archived">已归档</option>
                </select>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> 保存</button>
                <a href="content-management.jsp" class="btn btn-outline"><i class="fas fa-times"></i> 取消</a>
            </div>
        </form>
    </section>
</div>
<jsp:include page="footer.jsp" />
<script>
    // 根据类型显示/隐藏特定字段
    document.getElementById('type').addEventListener('change', function() {
        document.querySelectorAll('.type-fields').forEach(el => el.classList.remove('type-active'));
        const selectedType = this.value;
        if (selectedType) {
            document.getElementById(selectedType + '-fields').classList.add('type-active');
        }
    });
    // 封面图片预览
    document.getElementById('cover').addEventListener('change', function(e) {
        const file = e.target.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = function(event) {
                const previewContainer = document.getElementById('cover-preview-container');
                const preview = document.getElementById('cover-preview');
                previewContainer.style.display = 'block';
                preview.src = event.target.result;
            };
            reader.readAsDataURL(file);
        } else {
            document.getElementById('cover-preview-container').style.display = 'none';
        }
    });
</script>
</body>
</html>